﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Tyt
{
    public partial class Form1 : Form
    {
        Point PointQian;
        Point PointHou;
        bool IsTiaoQian = true;
        double XiShu = 0.00331;
        Point PointLeftUp;
        Point PointRightDown;

        #region 基本操作
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1_TextChanged(null, null);
            Text = PubFun.AppName + PubFun.GetVersion();
            richTextBox1.Text = PubFun.HelpStr;
            AppHotKey.RegKey(Handle, 1007, AppHotKey.KeyModifiers.None, Keys.F6);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            new Form2().ShowDialog(this);
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                XiShu = double.Parse(textBox1.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("微调设置不对,请输入一个小数。");
                return;
            }
        }
        protected override void WndProc(ref Message m)
        {
            const int WM_HOTKEY = 0x0312;
            switch (m.Msg)
            {
                case WM_HOTKEY:
                    switch (m.WParam.ToInt32())
                    {
                        case 1007:
                            Tiao();
                            break;
                    }
                    break;
            }
            base.WndProc(ref m);
        }
        #endregion

        #region 跳一跳
        void Tiao()
        {
            if (IsTiaoQian)
            {
                label7.Text = "F6跳跃：前";
                PointQian = new Point(Control.MousePosition.X, Control.MousePosition.Y);
            }
            else
            {
                label7.Text = "F6跳跃：后";
                TiaoHou();
            }
            IsTiaoQian = !IsTiaoQian;
        }
        void TiaoHou()
        {
                PointHou = new Point(Control.MousePosition.X, Control.MousePosition.Y);
            double len=Math.Sqrt((PointHou.X - PointQian.X) * (PointHou.X - PointQian.X) + 
                (PointHou.Y - PointQian.Y) * (PointHou.Y - PointQian.Y));

            int d= (int)(len * XiShu * 1000) ;
            if (d<=0)
            {
                MessageBox.Show("两次点击F6时，鼠标未移动。不要按住F6不放，点一下就行了。");
                return;
            }
            timer1.Interval = d;
            MouseHelper.SetCursorPos(PointHou.X, PointHou.Y);//开始跳
            MouseHelper.Down();
            timer1.Start();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            MouseHelper.Up();
        }
        #endregion

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("iexplore.exe", "http://www.cnblogs.com/bhss/p/8183019.html");
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("iexplore.exe", "//shang.qq.com/wpa/qunwpa?idkey=c5bae98453b8c394508aa06cd228261d7fcc7557704629b7ad3f97a407a7df52");
        }

    }
}
